from urllib import parse
from typing import Union, Tuple

import requests


class HTMLDownloader:
    """
    HTML 下载器
    """
    def __init__(self) -> None:
        self._headers = {
            "User-Agent":
            "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
        }

    def download(self, url: str) -> Union[Tuple[str, str], None]:
        """
        网页下载
        """
        if url:
            r = requests.get(
                url=url, 
                headers=self._headers
            )
            page = r.text
            url = parse.unquote(r.url)
            return page, url
        